package com.bjpowernode.springboot.controller;

import com.bjpowernode.springboot.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class MyController {

    @RequestMapping(value = "/each/list")
    public String eachList(Model model){
        List<User> userList=new ArrayList<>();

        for(int i=0;i<10;i++){
            User user=new User();
            user.setId(100+i);
            user.setUsername("张三"+i);
            user.setAge(20+i);
            userList.add(user);
        }
        model.addAttribute("userList",userList);
        return "each";
    }

    @RequestMapping(value = "/each/map")
    public String eachMap(Model model){
        Map<Integer,Object> userMap=new HashMap<>();

        for(int i=0;i<10;i++){
            User user=new User();
            user.setId(100+i);
            user.setUsername("张三"+i);
            user.setAge(20+i);
            userMap.put(i,user);
        }
        model.addAttribute("userMap",userMap);
        return "each";
    }

    @RequestMapping(value = "/each/listmap")
    public String listMap(Model model){
        List<Map> tList=new ArrayList<>();
        for(int i=0;i<2;i++){
            Map<Integer,Object> userMap=new HashMap<>();
            for(int j=0;j<2;j++){
                List<User> userList=new ArrayList<>();
                for(int k=0;k<3;k++){
                    User user=new User();
                    user.setId(100+k);
                    user.setUsername("张三"+k);
                    user.setAge(20+k);
                    userList.add(user);
                }
                userMap.put(j,userList);
            }
            tList.add(userMap);
        }
        model.addAttribute("tList",tList);
        return "each02";
    }
}
